<template>
  <el-dialog :title="title" :visible.sync="visible" width="900px" append-to-body>
    <el-form ref="form" inline :model="form" :rules="rules" label-width="170px">

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {add, getById, updateById} from "@/api/product/tourproduct";

export default {
  name: "create",
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      visible: false,
      // 表单参数
      form: {
        activeInd: "",
        amount: "",
        backTime: "",
        backWorkerId: "",
        checkIndex: "",
        ciden: "",
        contractContent: "",
        contractId: "",
        contractType: "",
        dispatchWorkerId: "",
        getTime: "",
        isNew: "",
        printNum: "",
        printTime: "",
        qrCodeUrl: "",
        saleOrderId: "",
        signingUrl: "",
        workerId: "",
        ycContract: "",
        ycState: "",
      },
      // 表单校验
      rules: {

      },
      options: {
        ycState: [
          {value: 0, label: '未提交'},
          {value: 1, label: '待审核'},
          {value: 2, label: '已审核'},
          {value: -1, label: '不通过'},
        ]
      },
    }
  },
  methods: {
    open(id) {
      if (id) {
        getById(id).then(response => {
          this.visible = true
          this.$nextTick(() => {
            this.form = response.data
          })
          this.title = "修改合同"
        })
      } else {
        this.visible = true
        this.$nextTick(() => {
          this.reset()
        })
        this.title = "新增产品"
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateById(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.$emit('confirm')
            })
          } else {
            add(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.$emit('confirm')
            })
          }
        }
      })
    },
    // 取消按钮
    cancel() {
      this.visible = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.$refs.form.resetFields()
    },
  }
}
</script>
